

class Watcher{
  constructor(vm,key,cb) {
    this.vm = vm;
    this.key = key;
    this.cb = cb;

    Dep.target = this;
    // vm[key] 得到值旧  hello vue
    this.oldValue = vm[key];
    Dep.target = null;
  }
  // 核心：更新视图
  update() {
    let newValue = this.vm[this.key];
    if (newValue == this.oldValue) {
      return; // 新值和旧值一样，不需要更新视图
    }
    this.cb(newValue)
  }
}